Skip to content

fix(cluster): a Redis outage must not crash replicas; resync caches on reconnect - #31721

Merged
objectstack-fleet[bot] merged 11 commits into
mainfrom
claude/project-thread-ku5w7f
Nov 9, 2026
Merged

objectstack-fleet[bot] merged 11 commits into
mainfrom
claude/project-thread-ku5w7f

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread

Fixes #31596

Clause-②: yes (widening)
Metadata-protocol: none

Measured on the built declarations (dist/index.d.ts of each touched package): new exports in @objectstack/service-cluster (CLUSTER_RESYNC_EVENT, ClusterDriverLiveness, offerClusterDriverLiveness, onClusterResync, readClusterDriverHealth, describeConnectionError, redactCredentials and five types) and @objectstack/service-cluster-redis (REDIS_COMMAND_TIMEOUT_MS, watchRedisConnection, describeRedisTarget), optional members RedisDriverOptions.logger, RedisPubSubOptions.liveness, DatasourceAdminServiceConfig.listConvergeNames and the connector-credential door's resyncFromCluster, and public methods MetadataManager.resyncClusterPubSub(), DatasourceAdminService.resyncDatasourceMutationPubSub(), AutomationEngine.resyncConnectorCredentialPubSub(). Nothing is removed or made required. The claim read no; the measurement says yes (widening). No metadata an author writes changes.

维护者速读

  • 改了什么:多副本 Redis 集群下,Redis 宕机不再让副本进程崩溃;宕机只记一条告警,恢复后各缓存自动重新同步。
  • 为什么改:此前定时任务拿不到集群锁时抛出未处理的拒绝,每个副本在下一次定时触发时退出;宕机期间丢失的缓存失效通知也要等到重启才会恢复。
  • 风险与回滚:单节点(默认内存驱动)完全不变;Redis 驱动新增默认 2 秒命令超时,单条命令超过 2 秒会失败(驱动和共享缓存的命令都是 O(1))。回滚即撤销本 PR。
  • 先看:service-job 的 cron-job-adapter.ts(不再崩溃)和 service-cluster 的新文件 cluster-resync.ts(cluster.resync 事件)。
  • 两分钟验证:在装有 redis-server 的机器上跑 service-cluster-redis 的 redis-outage.real-redis.test.ts,它会在两个运行中的内核下停掉再启动 Redis。
  • 需要你做的:无;标题里的 ! 是否保留由席位复核(见 Acceptance notes)。

What changes

  • No crash on a dead lock (@objectstack/service-job). CronJobAdapter leader-elects every scheduled fire on the cluster lock. A rejected acquire used to escape the timer callback as an unhandled rejection and end the process. It now skips that fire, and the next tick retries. A failed release is absorbed, and the lease expires on its TTL. The adapter logs one warning per lock outage and one info line when the lock answers again. No process-wide unhandledRejection handler is added. runScheduled is the only lock caller in the job adapters.
  • The driver watches its connections (@objectstack/service-cluster-redis). The command connection and the pub/sub subscriber both get an error / close / ready listener (watchRedisConnection). ioredis no longer prints Unhandled error event per reconnect attempt. The driver logs one warning per outage, naming host:port and never the URL or a password, and one info line when the connection returns. New option driverOptions.logger.
  • Bounded commands. createRedisClient() sets commandTimeout: REDIS_COMMAND_TIMEOUT_MS (2000 ms). ioredis arms it before offline queueing, so it bounds queued commands too. client.duplicate() inherits it, so the shared cache's derived connection is bounded as well.
  • Driver health and cluster.resync (@objectstack/service-cluster). ClusterDriverLiveness is the connection state machine a remote driver feeds. Read health with readClusterDriverHealth(cluster), which returns { driver, nodeId, state: 'unknown' | 'up' | 'down', since, outages, lastError? }, or undefined on the memory driver. This is the accessor feat(runtime): /ready reports cluster driver health when multi-replica is declared (#3814) #31601 reads. When every failed connection is ready again, the liveness emits ONE local event, cluster.resync (CLUSTER_RESYNC_EVENT). Subscribe with onClusterResync(cluster, handler), which returns a disposer. The event is never published to peers. On the memory driver the subscription is an inert no-op. feat(cluster): settings changes reach every replica (settings lane) (#3814 F3b) #31597 joins here. The liveness is offered on the cluster instance under a Symbol.for key, as driver-connection.ts already does.
  • The four caches re-read on it.
    • MetadataClusterBridgePlugin subscribes once and calls each attached lane's resync seam, with per-lane failure isolation:
      • metadata list caches: MetadataManager.resyncClusterPubSub() drops every list cache and the endpoint index; registry entries are kept.
      • datasource pools: DatasourceAdminService.resyncDatasourceMutationPubSub() re-converges every datasource in the shared rows plus every pool this replica holds.
      • connector credentials: AutomationEngine.resyncConnectorCredentialPubSub() runs the reconcile a peer's signal runs.
    • AuthzClusterBridgePlugin advances the engine's write epoch with reason remote, which retires cached grants exactly as a delivered remote hint does.

R3: the single-node default path is unchanged (the memory driver offers no liveness, so no listener, latch or resync runs on it). Nothing switches on by itself: every new path needs the redis driver connected, and the bridges still attach only when isInProcessClusterDriver is false. The split-brain guard is untouched, and the deploy README's "multi-node unsupported" line is untouched.

Tests

  • service-cluster-redis/src/redis-outage.real-redis.test.ts (new) uses a real redis-server with a password. It is skipped where the binary is absent. Two LiteKernel replicas, each with the redis cluster driver and a cron job on a 100 ms interval, share one Redis. The Redis process is SIGKILLed and restarted on the same port. Pinned:

    • no unhandled rejection;
    • exactly one "lost its connection" line and one "reconnected" line per replica, with no password anywhere;
    • at most one cron warning per replica;
    • no fire during the outage, and the next fire after the return runs;
    • a hint published during the outage is lost, and the peer converges on its single cluster.resync;
    • a hint published after the return reaches the peer.

    The second case dials a black-holed TCP server: a GET on the cache's duplicate()d connection rejects with timed out in about 2 s, not about 30 s.

  • service-cluster/src/cluster-resync.test.ts (new) covers:

    • one warning per outage;
    • resync once, only when every failed source is back;
    • no resync on first connect;
    • handler isolation, close() and redaction;
    • the offer is non-enumerable;
    • CONTROL: the memory driver gives no health and an inert subscription.
  • Each lane got a new describe:

    • metadata-cluster-bridge-plugin.test.ts: each lane is called once per outage, a failing lane is isolated, nothing runs after shutdown, and CONTROL memory.
    • authz-cluster-bridge-plugin.test.ts: one bump('remote') while bridged, nothing after shutdown, and CONTROL TTL 0.
    • metadata-manager-cluster.test.ts, datasource-cluster-convergence.test.ts, connector-credential-cluster.test.ts: a lossy bus loses a peer write, and the resync converges it (CREATE and DELETE for datasources, plus a no-churn case). Each has a CONTROL with no transport.
    • cron-job-adapter.leader.test.ts: a rejected acquire across 10 ticks gives one warning and no rejection, recovery logs once, a release rejection is absorbed, and a timer-driven fire raises no unhandled rejection.
  • Forced test edits: none. The authz bridge harness now hands back a stable objectql service carrying a writeEpoch seam; no existing assertion changed.

  • Test resolution (from pnpm check:test-source-alias):

  • Ablations (each through scripts/ablation-replace.mjs; every one landed and went red, and every restore left git diff HEAD empty):

    Ablation Red tests
    A1: acquire try/catch removed 3 red, including the timer-driven unhandled-rejection pin
    A2: cron warn latch 3 red, 10 warnings instead of 1
    A3: liveness warn latch 2 red, 26 instead of 1
    A4: resync before every source is back 1 red
    A5: redaction 2 red
    A6: commandTimeout removed the black-hole case times out at 10 s
    A7: resync on first connect 3 red
    B1: metadata bridge shutdown detach 1 red
    B2: authz shutdown detach 1 red
    B3 / B4 / B5: metadata, datasource and automation no-transport guards 1 red each
    B6: datasource connectivity check (no churn) 1 red

    B5 first stayed green against a weaker control. That control was strengthened in its own commit, and B5 then went red.

Acceptance notes

  • The metadata.mutated registry lane (lane 2) has no resync seam yet. It still converges per item on delivered signals and fully at boot. I recommend a follow-up card.

  • Against a black-holed store the health reads unknown or up until the socket errors. The command bound, not the health, is what stops a caller hanging.

  • A SET NX that timed out client-side may still land on the server, so a lock can stay held until its TTL. The fire is skipped, never run twice.

  • Out of the file surface:

    • The shared cache's derived connection (service-cache/src/cache-service-plugin.ts, base.duplicate()) has no error listener of its own, so it still prints ioredis' Unhandled error event during an outage.
    • The messaging dispatchers warn on each backed-off tick.
    • check:test-source-alias's source-reach remedy for a lazily loaded @objectstack/driver-memory (a module-top import) is a binding that check:driver-memory-census refuses. Any edited test that reaches the default driver factory meets that conflict. This PR resolves it by aliasing to source.

    These are left for a follow-up.

  • The ! in the title: on a single node nothing changes. On the redis driver the only new default is the 2 s command bound. The changeset is patch with no BREAKING banner. The seat re-states whether the ! stands.

Verification

  • Per touched package, a full vitest run, pnpm typecheck and package-scoped lint (root eslint on the directory, --no-inline-config) all exit 0:

    Package Test files Tests
    service-cluster 9 130
    service-cluster-redis 4 41 (the real-redis file included)
    service-job 11 125
    metadata 71 984
    service-datasource 74 1299
    service-automation 266 3458

    The datasource suite was re-run on the final head. Lint on scripts/check-test-source-alias.mjs exits 0.

  • Full dogfood (pnpm --filter @objectstack/dogfood test, on 2cb8ab79): 440 test files passed and 3 skipped; 3652 tests passed and 41 skipped. The only commit after it touches test resolution and a gate registry, not package source.

  • dispatch-gates.mjs --commands was derived on the final head bf098837 and gave 105 commands. Each was run (all exit 0) and reconciled with --ran: 105 derived, 105 run, 0 NOT-MEASURED.


Generated by Claude Code

… instance held

The single-node control now reproduces the lost-correction shape with no
transport on either replica, so it goes red if the resync reconciles
without one.

Claude-Session: https://claude.ai/code/session_01ADHkmT4XhMdYmBfwHE4sQ7
Co-authored-by: Claude <noreply@anthropic.com>
…ptional

A door attached through setConnectorCredentialDoor() without the new
member still type-checks, and a resync on it does nothing. The
changeset now declares the measured widening.

Claude-Session: https://claude.ai/code/session_01ADHkmT4XhMdYmBfwHE4sQ7
Co-authored-by: Claude <noreply@anthropic.com>
…oad drivers at collection

The real-redis outage test now resolves @objectstack/core and
@objectstack/service-job through anchored source aliases, and the
datasource convergence test pays its drivers' first load at module top.

Claude-Session: https://claude.ai/code/session_01ADHkmT4XhMdYmBfwHE4sQ7
Co-authored-by: Claude <noreply@anthropic.com>
…nding it in a test

A module-top import of the memory driver satisfied the source-reach
rule but is a new arrival in the memory-driver census. The package's
vitest config now aliases it to source, which retires the shrink-only
registry entry that let it resolve through dist.

Claude-Session: https://claude.ai/code/session_01ADHkmT4XhMdYmBfwHE4sQ7
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/xl dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 6 package(s): @objectstack/metadata, @objectstack/service-automation, @objectstack/service-cluster-redis, @objectstack/service-cluster, @objectstack/service-datasource, @objectstack/service-job, touching 76 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/services/service-cluster-redis/vitest.config.ts, packages/services/service-datasource/vitest.config.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

16 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 90cea476dedee4bb2586f60b4f469bba67904cf3.

⛔ 5 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/services/service-cluster-redis/vitest.config.ts, packages/services/service-datasource/vitest.config.ts) — pages documenting those are invisible to this run
  • 14 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 231 client-bound route-ledger rows — the other 166 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 166: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 107 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 25 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 90cea476dedee4bb2586f60b4f469bba67904cf3 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 8cafa34b6c583efdb7370284df595fe01f81d9ea — the merge of head f2661d7099a0458cb377090860c18a573d4c4dd1 into base 90cea476dedee4bb2586f60b4f469bba67904cf3, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 8cafa34b6c583efdb7370284df595fe01f81d9ea && git checkout 8cafa34b6c583efdb7370284df595fe01f81d9ea
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 90cea476dedee4bb2586f60b4f469bba67904cf3 f2661d7099a0458cb377090860c18a573d4c4dd1 && git checkout -B drift-repro 90cea476dedee4bb2586f60b4f469bba67904cf3 && git merge --no-ff f2661d7099a0458cb377090860c18a573d4c4dd1

node scripts/docs-audit/affected-docs.mjs --json 90cea476dedee4bb2586f60b4f469bba67904cf3

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 90cea476dedee4bb2586f60b4f469bba67904cf3 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…the redis outage settings

Claude-Session: https://claude.ai/code/session_01ADHkmT4XhMdYmBfwHE4sQ7
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · os-steve · session_01ADHkmPF1skfu2kx89BEXZi

席位 ACCEPT · head ad6180c576ee9c276cb390c629712e70cb7c275c

面:declaration(Clause-②: yes (widening),无 schema、无受治理路径),按 TIER_DEFAULT 由席位审。

@objectstack-fleet objectstack-fleet Bot changed the title fix(cluster)!: a Redis outage must not crash replicas; resync caches on reconnect fix(cluster): a Redis outage must not crash replicas; resync caches on reconnect Nov 9, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 9, 2026 00:41
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 9, 2026 00:41
…robe

main added probeClusterDriverHealth() and its ClusterDriverHealth type.
The passive reading this branch exports is now ClusterDriverLivenessHealth,
and the docs say which reading is which.

Claude-Session: https://claude.ai/code/session_01ADHkmT4XhMdYmBfwHE4sQ7
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · os-steve · session_01ADHkmPF1skfu2kx89BEXZi

席位 ACCEPT · 冲突轮 · head f2661d7099a0458cb377090860c18a573d4c4dd1

  • 冲突来源:main 上的 feat(runtime): /ready reports cluster driver health when multi-replica is declared #31711(driver-health.ts,导出 probeClusterDriverHealth 和 type ClusterDriverHealth)和 feat(cloud-connection)!: refuse marketplace install-local when replicas are declared on the Redis driver #31712(multi-replica.ts)。本 PR 原来也导出一个同名不同形的 ClusterDriverHealth,公共名字撞了。
  • 处理:合入 main,没有 rebase 或 force。本 PR 的类型改名为 ClusterDriverLivenessHealth,readClusterDriverHealth 改为返回它;main 上的 ClusterDriverHealth / probeClusterDriverHealth 原样不动。index.ts 两块导出都保留,各加一行注释:主动探测(PING,即 /ready 报的)和被动读连接状态,回答的是两个不同的问题。cluster-resync.ts 的文档和 cluster.mdx §8 也写明两者的关系;changeset 的导出名单已同步。
  • 这些新名字都还没发布过,改名不涉及兼容问题。Clause-② 仍是 yes (widening)。
  • 卡片线程验证:service-cluster 143/143(含 main 新增的测试),service-cluster-redis 41/41(含真实 Redis),typecheck 和 lint 都过,runtime typecheck 也过。

落地条件:门禁对账和 CI 全绿,然后 relay pr_ready 已是 ready → automerge_enable。

@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 9e1f1f9 Nov 9, 2026
68 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-ku5w7f branch November 9, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cluster)!: a Redis outage must not crash replicas; resync caches on reconnect (#3814 F3a)

1 participant